﻿namespace ChinaUnicom.ViewModels
{
    using ChinaUnicom.Models;
    using System.ComponentModel;
    using System.Linq;

    public class PackageDetailsContext : PageContext, INotifyPropertyChanged
    {
        public PackageDetailsContext(string name)
        {
            item = Context.Current.Package.Items.FirstOrDefault(x => x.Name == name);
            if (item == null)
            {
                item = new Item();
                item.Name = name;
            }
        }

        Item item;
        public Item Item
        {
            get { return item; }
            set
            {
                if (value != this.item)
                {
                    item = value;
                    NotifyPropertyChanged("Item");
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
